home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / a86v400.zip / A08.DOC < prev    next >
Text File  |  1994-12-21  |  26KB  |  661 lines

  1. CHAPTER 8   NUMBERS AND EXPRESSIONS
  2.  
  3.  
  4. Numbers and Bases
  5.  
  6. A86 supports a variety of formats for numbers.  In non-computer
  7. life, we write numbers in a decimal format.  There are ten
  8. digits, 0 through 9, that we use to describe numbers; and each
  9. digit position is ten times as significant as the position to its
  10. right.   The number ten is called the "base" of the decimal
  11. format.  Computer programmers often find it convenient to use
  12. other bases to specify numbers used in their programs.  The most
  13. commonly-used bases are two (binary format), sixteen (hexadecimal
  14. format), and eight (octal format).
  15.  
  16. The hexadecimal format requires sixteen digits.  The extra six
  17. digits beyond 0 through 9 are denoted by the first six letters of
  18. the alphabet: A for ten, B for eleven, C for twelve, D for
  19. thirteen, E for fourteen, and F for fifteen.
  20.  
  21. In A86, a number must always begin with a digit from 0 through 9,
  22. even if the base is hexadecimal.  This is so that A86 can
  23. distinguish between a number and a symbol that happens to have
  24. digits in its name.  If a hexadecimal number would begin with a
  25. letter, you precede the letter with a zero.  For example, hex A0,
  26. which is the same as decimal 160, would be written 0A0.
  27.  
  28. Because it is necessary for you to append leading zeroes to many
  29. hex numbers, and because you never have to do so for decimal
  30. numbers, I decided to make hexadecimal the default base for
  31. numbers with leading zeroes.  Decimal is still the default base
  32. for numbers beginning with 1 through 9.
  33.  
  34. Large numbers can be given as the operands to DD, DQ, or DT
  35. directives.  For readability, you may freely intersperse
  36. underscore characters anywhere with your numbers.
  37.  
  38. The default base can be overridden, with a letter or letters at
  39. the end of the number: B or xB for binary, O or Q for octal, H
  40. for hexadecimal, and D or xD for decimal.  Examples:
  41.  
  42.  077Q       octal, value is 8*7 + 7 = 63 in decimal notation
  43.  123O       octal if the "O" is a letter: 64 + 2*8 + 3 = 83 decimal
  44.  1230       decimal 1230: shows why you should use "Q" for octal!!
  45.  01234567H  large constant
  46.  0001_0000_0000_0000_0003R          real number specified in hexadecimal
  47.  100D       superfluous D indicates decimal base
  48.  0100D      hex number 100D, which is 4096 + 13 = 5009 in decimal
  49.  0100xD     decimal 100, since xD overrides the default hex format
  50.  0110B      hex 110B, which is 4096 + 256 + 11 = 4363 in decimal
  51.  0110xB     binary 4+2 = 6 in decimal notation
  52.  110B       also binary 4+2 = 6, since "B" is not a decimal digit
  53.                                                               8-2
  54.  
  55. The last five examples above illustrate why an "x" is sometimes
  56. necessary before the base-override letter "B" or "D".  If that
  57. letter can be interpreted as a hex digit, it is; the "x" forces
  58. an override interpretation for the "B" or "D".  By the way, the
  59. usage of lower case for x and upper case for the following
  60. override letter is simply a recommendation; A86 treats upper-and
  61. lower-case letters equivalently.
  62.  
  63. A86 also accepts a "base" of K.  The number preceding the K is
  64. interpreted as a decimal number which is multplied by 1024.
  65. Thus, 2K is 2048, 16K is 16384, etc.
  66.  
  67.  
  68. The RADIX Directive
  69.  
  70. The above-mentioned set of defaults (hex if leading zero, decimal
  71. otherwise) can be overridden with the RADIX (or, for
  72. compatibility, .RADIX) directive.  The RADIX directive consists
  73. of the word RADIX followed by a number from 2 to 16.  The default
  74. base for the number is ALWAYS decimal, regardless of any (or no)
  75. previous RADIX commands.  The number gives the default base for
  76. ALL subsequent numbers, up to (but not including) the next RADIX
  77. command.  If there is no number following RADIX, then A86 returns
  78. to its initial mixed default of hex for leading zeroes, decimal
  79. for other leading digits.
  80.  
  81. As an alternative to the RADIX directive, I provide the D switch,
  82. which causes A86 to start with decimal defaults.  You can put +D
  83. into the A86 command invocation, or into the A86 environment
  84. variable.  The first RADIX command in the program will override
  85. the D switch setting.
  86.  
  87. Following are examples of radix usage.  The numbers in the
  88. comments are all in decimal notation.
  89.  
  90.   DB 10,010     ; produces 10,16 if RADIX was not seen yet
  91.                 ;   and +D switch was not specified
  92. RADIX 10
  93.   DB 10,010     ; produces 10,10
  94. RADIX 16
  95.   DB 10,010     ; produces 16,16
  96. RADIX 3         ; for Martian programmers in Heinlein novels
  97.   DB 10,100     ; produces 3,9
  98. RADIX
  99.   DB 10,010     ; produces 10,16
  100.                                                               8-3
  101.  
  102. Floating Point Initializations
  103.  
  104. A86 allows floating point numbers as the operands to DD, DQ, and
  105. DT directives.  The numbers are encoded according to the IEEE
  106. standard, followed by the 8087 and 287 coprocessors.  The format
  107. for floating point constants is as follows: First, there is a
  108. decimal number containing a decimal point.  There must be a
  109. decimal point, or else the number is interpreted as an integer.
  110. There must also be at least one decimal digit, either to the left
  111. or right of the decimal point, or else the decimal point is
  112. interpreted as an addition (structure element) operator.
  113. Optionally, there may follow immediately after the decimal number
  114. the letter E followed by a decimal number.  The E stands for
  115. "exponent", and means "times 10 raised to the power of".  You may
  116. provide a + or - between the E and its number.  Examples:
  117.  
  118.   0.1             constant one-tenth
  119.   .1              the same
  120.   300.            floating point three hundred
  121.   30.E1           30 * 10**1; i.e., three hundred
  122.   30.E+1          the same
  123.   30.E-1          30 * 10**-1; i.e., three
  124.   30E1            not floating point: hex integer 030E1
  125.   1.234E20        scientific notation: 1.234 times 10 to the 20th
  126.   1.234E-20       a tiny number: 1.234 divided by 10 to the 20th
  127.  
  128.  
  129.  
  130. Overview of Expressions
  131.  
  132. Most of the operands that you code into your instructions and
  133. data initializations will be simple register names, variable
  134. names, or constants.  However, you will regularly wish to code
  135. operands that are the results of arithmetic calculations,
  136. performed either by the machine when the program is running (for
  137. indexing), or by the assembler (to determine the value to
  138. assemble into the program).  A86 has a full set of operators that
  139. you can use to create expressions to cover these cases.  They are
  140. given in the "Descriptions of Operators and Specifiers" section
  141. later in this chapter.
  142.  
  143.  
  144. Types of Expression Operands
  145.  
  146. Numbers and Label Addresses
  147.  
  148. A number or constant (16-bit number) can be used in most
  149. expressions.   A label (defined with a colon) is also treated as
  150. a constant and so can be used in expressions.
  151.  
  152. Variables
  153.  
  154. A variable stands for a byte- or word-memory location.   You may
  155. add or subtract constants from variables; when you do so, the
  156. constant is added to the address of the variable.  You typically
  157. do this when the variable is the name of a memory array.
  158.                                                               8-4
  159.  
  160. Index Expressions
  161.  
  162. An index expression consists of a combination of a base register
  163. [BX] or [BP], and/or an index register [SI] or [DI], with an
  164. optional constant added or subtracted.   You will usually want to
  165. precede the bracketed expression with B, W, or D; to specify the
  166. kind of memory unit (byte, word, or doubleword) you are referring
  167. to.  The expression stands for the memory unit whose address is
  168. the run-time value(s) of the base and/or index registers added to
  169. the constant.  See the Effective Address section and the
  170. beginning of this chapter for more details on indexed memory.
  171.  
  172.  
  173. Descriptions of Operators and Specifiers
  174.  
  175. HIGH/LOW
  176.  
  177. Syntax:  HIGH  operand
  178.          LOW  operand
  179.  
  180. These operators are called the "byte isolation" operators.  The
  181. operand  must evaluate to a 16-bit number.   HIGH returns the
  182. high order byte of the number; LOW the low order byte.
  183.  
  184. For example,
  185.  
  186.   MOV AL,HIGH(01234)     ; AL = 012
  187.   TENHEX EQU LOW(0FF10)  ; TENHEX = 010
  188.  
  189. These operators can be applied to each other.   The following
  190. ident